﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Testing
{
    public partial class DrawSquare : Form
    {
        public DrawSquare()
        {
            InitializeComponent();
        }

        // Store the squares that are painted on the form. 
        private ArrayList squares = new ArrayList();
        // This code reacts to the Form.MouseDown event. 
        private void DrawSquare_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
        { 
            //Rectangle square = new Rectangle(e.X, e.Y, 20, 20); 
            //squares.Add(square); 
            //this.Invalidate(); 

            //Rectangle square = new Rectangle(e.X, e.Y, 20, 20); 
            //squares.Add(square);
            //Graphics g = this.CreateGraphics(); 
            //DrawRectangle(square, g); 
            //g.Dispose();


            Rectangle square = new Rectangle(e.X, e.Y, 20, 20); 
            squares.Add(square); 
            this.Invalidate(square);
        } 

        private void DrawSquare_Paint(object sender, PaintEventArgs e)
        {
            //Pen drawingPen = new Pen(Color.Red, 10); 
            //foreach (Rectangle square in squares) 
            //{ 
            //    e.Graphics.DrawRectangle(drawingPen, square); 
            //} 
            //pnlSquares.Text = " " + squares.Count.ToString() + " squares";

            foreach (Rectangle square in squares) {
                DrawRectangle(square, e.Graphics); 
            }
        }

        // This procedure performs the actual drawing, and is called by 
        // DrawSquare_MouseDown and DrawSquare_Paint. 
        private void DrawRectangle(Rectangle rect, Graphics g) { 
            Pen drawingPen = new Pen(Color.Red, 10); 
            g.DrawRectangle(drawingPen, rect); 
        } 

        

        private void DrawSquare_Load(object sender, EventArgs e)
        {
            
        }

        private void DrawSquare_MouseMove(object sender, MouseEventArgs e)
        {
            //Rectangle square = new Rectangle(e.X, e.Y, 20, 20);
            //squares.Add(square);
            //this.Invalidate(square);
        }

        
    }
}
